package com.mydemo.game.runStage;

import com.mydemo.entity.Car;
import com.mydemo.entity.Save;

import java.util.ArrayList;
import java.util.List;

import static java.lang.Thread.sleep;

public class RunStage {
    public static final Save runStage(Save save){
        System.out.println("开始营业");
        try {
            sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        boolean flag = true;
//            获取到所有有司机的车辆，让他们运营
//            运营是每辆车每天的行动次数*单价*座位数
        List<Car> carList = new ArrayList<>();
        if (save.getCarList() != null) {
            carList = save.getCarList();
        } else {
            System.out.println("没有可运营的车辆");
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            return save;
        }
        int moneyToday = 0;
        for (Car car :
                carList) {
            if (car.isDrive()) {
                moneyToday += car.getDayRunTime() * car.getPrice() * car.getSeatNum();
            }
        }
        System.out.println("今天的营业额是：" + moneyToday);
        save.setMoney(save.getMoney() + moneyToday);
        System.out.println("当前总资产是：" + save.getMoney());
        System.out.println("++++++++++++++++++++");
        return save;
    }
}
